/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.gwt.apps.client.program;

import net.bioteam.appweb.gwt.apps.client.StaticHolder;
import net.bioteam.appweb.gwt.apps.client.Util.ApplicationCallBack;
import net.bioteam.appweb.gwt.apps.clientandserver.program.GetProgramSpec;
import net.bioteam.appweb.submit.ProgramValueBean;

import com.smartgwt.client.util.SC;


public class ProgramFormLoader extends ApplicationCallBack<ProgramValueBean>
{

	@Override
	protected boolean onFailureBefore(Throwable caught)
	{
		//StaticHolder.pbar.reset(true);
		return true;
	}

	String ptype;
	String pvalue;


	public ProgramFormLoader(String ptype, String pvalue)
	{
		this.ptype=ptype;
		this.pvalue=pvalue;
	}

	public void execute()
	{
		StaticHolder.setStatusMessage("reinitializing application form ..", 6);
		GetProgramSpec.Util.getInstance().getProgram(ptype, pvalue, this);
	}

	public String getHistoryToken()
	{

		return "appnode_" + ptype + "_" + pvalue;
	}

	@Override
	protected void onFailureAfter(Throwable caught)
	{
		StaticHolder.loadingWindow.hide();
		SC.warn("Server Error:" + caught.getMessage(), StaticHolder.dumpB);
	}

	@Override
	protected void onSuccessAfter(ProgramValueBean result)
	{
		
		ProgramForm form=new ProgramForm();
		form.setBean(result);
		
		
		StaticHolder.programForm=form;
		StaticHolder.programFormHodler.setProgramForm(form);
		StaticHolder.content.switchPanel(StaticHolder.programFormHodler);
		StaticHolder.loadingWindow.hide();
	}

}

